package easy.分发饼干;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;


/**
 * @author zhengTao
 * @version 1.0
 * @description: easy.分发饼干
 * @date 2022/11/20 10:21
 */
public class Demo455 {
    public static void main(String[] args) {
        int[] g={10,9,8,7};
        int[] s={5,6,7,8};
        int contentChildren = findContentChildren(g, s);
        System.out.println(contentChildren);
    }
    public static int findContentChildren(int[] g, int[] s) {
        //先小孩胃口排序
        Arrays.sort(g);
        //根据饼干大小排序
        Arrays.sort(s);
        int count=0;
        //胃口最小的小孩，找到满足该小小孩胃口的最小饼干，，找到后移除
        List<Integer> collect = Arrays.stream(s).boxed().collect(Collectors.toList());
        for (int i = 0; i < g.length; i++) {
            for (int j = 0; j < collect.size(); j++) {
                if(j==collect.size()-1&&collect.get(j)<g[i]){
                    return count;
                }
                if(collect.get(j)>=g[i]){
                    count++;
                    collect.remove(j);
                    break;
                }
            }
        }
        return count;
    }
}
